package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PostComments;
import com.ruoyi.system.service.IPostCommentsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 帖子评论Controller
 * 
 * @author zrj
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/system/postComments")
public class PostCommentsController extends BaseController
{
    @Autowired
    private IPostCommentsService postCommentsService;

    /**
     * 查询帖子评论列表
     */
    @PreAuthorize("@ss.hasPermi('system:postComments:list')")
    @GetMapping("/list")
    public TableDataInfo list(PostComments postComments)
    {
        startPage();
        List<PostComments> list = postCommentsService.selectPostCommentsList(postComments);
        return getDataTable(list);
    }

    /**
     * 导出帖子评论列表
     */
    @PreAuthorize("@ss.hasPermi('system:postComments:export')")
    @Log(title = "帖子评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PostComments postComments)
    {
        List<PostComments> list = postCommentsService.selectPostCommentsList(postComments);
        ExcelUtil<PostComments> util = new ExcelUtil<PostComments>(PostComments.class);
        util.exportExcel(response, list, "帖子评论数据");
    }

    /**
     * 获取帖子评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:postComments:query')")
    @GetMapping(value = "/{postCommentId}")
    public AjaxResult getInfo(@PathVariable("postCommentId") Long postCommentId)
    {
        return success(postCommentsService.selectPostCommentsByPostCommentId(postCommentId));
    }

    /**
     * 新增帖子评论
     */
    @PreAuthorize("@ss.hasPermi('system:postComments:add')")
    @Log(title = "帖子评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PostComments postComments)
    {
        return toAjax(postCommentsService.insertPostComments(postComments));
    }

    /**
     * 修改帖子评论
     */
    @PreAuthorize("@ss.hasPermi('system:postComments:edit')")
    @Log(title = "帖子评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PostComments postComments)
    {
        return toAjax(postCommentsService.updatePostComments(postComments));
    }

    /**
     * 删除帖子评论
     */
    @PreAuthorize("@ss.hasPermi('system:postComments:remove')")
    @Log(title = "帖子评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{postCommentIds}")
    public AjaxResult remove(@PathVariable Long[] postCommentIds)
    {
        return toAjax(postCommentsService.deletePostCommentsByPostCommentIds(postCommentIds));
    }
}
